home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / parsingcommandline / example7.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  4KB  |  120 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Parsing Command Line        Tulevagen 22       */
  8. /* File:    Example7.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-06                                       */
  11. /* Version: 1.0                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to use the FindArg() function.  */
  21. /* We simply use it to scan the command line template and return */
  22. /* the position of each command template.                        */
  23.  
  24.  
  25.  
  26. /* Include the dos library definitions: */
  27. #include <dos/dos.h>
  28.  
  29. /* Include information about the argument parsing routine: */
  30. #include <dos/rdargs.h>
  31.  
  32. /* Now we include the necessary function prototype files:         */
  33. #include <clib/dos_protos.h>       /* General dos functions...    */
  34. #include <clib/exec_protos.h>      /* System functions...         */
  35. #include <stdio.h>                 /* Std functions [printf()...] */
  36. #include <stdlib.h>                /* Std functions [exit()...]   */
  37.  
  38.  
  39.  
  40. /* Here is our command line template: (Note that it consists of   */
  41. /* three command templates. First we have the "SoundFile/A" which */
  42. /* has the position 0, then the "V=Volume/K/N" which has position */
  43. /* 1, and finally the "F=Filter/S" which has the position 2.)     */
  44. #define MY_COMMAND_LINE_TEMPLATE "SoundFile/A,V=Volume/K/N,F=Filter/S"
  45.  
  46.  
  47.  
  48. /* Set name and version number: */
  49. UBYTE *version = "$VER: AmigaDOS/ParsingCommandLine/Example7 1.0";
  50.  
  51.  
  52.  
  53. /* Declare an external global library pointer to the Dos library: */
  54. extern struct DosLibrary *DOSBase;
  55.  
  56.  
  57.  
  58. /* Declared our own functions: */
  59.  
  60. /* Our main function: */
  61. int main( int argc, char *argv[] );
  62.  
  63.  
  64.  
  65. /* Main function: */
  66.  
  67. int main( int argc, char *argv[] )
  68. {
  69.   /* Store the command template position here: */
  70.   int template_position;
  71.   
  72.   
  73.   
  74.   /* We need dos library version 37 or higher: */
  75.   if( DOSBase->dl_lib.lib_Version < 37 )
  76.   {
  77.     /* Inform the user: */ 
  78.     printf( "This program needs Dos Library V37 or higher!\n" );
  79.  
  80.     /* Exit with an error code: */
  81.     exit( 20 );
  82.   }
  83.  
  84.  
  85.  
  86.   /* Print heading: */
  87.   printf( "Command Template  Position\n" );
  88.   printf( "--------------------------\n" );
  89.  
  90.  
  91.  
  92.   /* Which position has the comman template "SoundFile"? */
  93.   template_position = FindArg( MY_COMMAND_LINE_TEMPLATE, "SoundFile" );
  94.  
  95.   /* Print the position: */
  96.   printf( "SoundFile         %d\n", template_position );
  97.  
  98.  
  99.  
  100.   /* Which position has the comman template "Filter"? */
  101.   template_position = FindArg( MY_COMMAND_LINE_TEMPLATE, "Filter" );
  102.  
  103.   /* Print the position: */
  104.   printf( "Filter            %d\n", template_position );
  105.  
  106.  
  107.  
  108.   /* Which position has the comman template "Volume"? */
  109.   template_position = FindArg( MY_COMMAND_LINE_TEMPLATE, "Volume" );
  110.  
  111.   /* Print the position: */
  112.   printf( "Volume            %d\n", template_position );
  113.  
  114.  
  115.  
  116.   /* The End! */
  117.   exit( 0 );
  118. }
  119.  
  120.